#pragma once

#include <iostream>
#include <vector>

typedef void(*func_t)();//函数指针

//每一个任务都是4字节（整形）
#define COMMAND_LOG 0
#define COMMAND_MYSQL 1
#define COMMAND_REQEUST 2

void PrintLog()
{
    std::cout << "子进程：" << getpid() << "，正在执行日志打印任务..." << std::endl;
}

void InsetrMySQL()
{
    std::cout << "子进程：" << getpid() << "，正在执行数据库任务..." << std::endl;
}

void NetRequest()
{
    std::cout << "子进程：" << getpid() << "，正在执行网络任务..." << std::endl;
}

class Task
{
public:
    Task()
    {
        //初始化任务
        funcs.push_back(PrintLog);
        funcs.push_back(InsetrMySQL);
        funcs.push_back(NetRequest);
    }

    void Execute(int command)
    {
        if(command >= 0 && command < funcs.size())
            funcs[command](); //执行任务
    }

    ~Task()
    {}
public:
    std::vector<func_t> funcs;
};
